TITLE MASM Template						(main.asm)

; Description:
; 
; Revision date:

INCLUDE Irvine32.inc 
;
;	Reverse a String Using the Stack 
;	Author: Phil Hartley
;

.data
string	BYTE	"This is a string", 0
.code
main PROC
	mov EDX, OFFSET string
	mov EAX, 0					; Clear accumulator
	mov ECX, LENGTHOF string - 1		; Set loop counter to the length of the string (not including the terminating 0)
	mov ESI, 0					; Use ESI for offsetting from string
	
pushLoop:
	mov AL, string[ESI]				; Load the byte pointed to by offset into AL
	push AX						; Push AX onto the stack (you can push only 6 or 32 bit values
	inc ESI						; Move ESI onto the next byte
	loop pushLoop
	
	mov ECX, LENGTHOF string - 1		; Set up loop counter as above
	mov ESI, 0					; Also, as above
	
popLoop:
	pop AX						; pop 16 bits into AX
	mov string[ESI], AL				; Write a byte into the string
	inc ESI						; Onto the next byte
	loop popLoop
	
	mov EDX, OFFSET string			; Write out the resulting string
	call WriteString
	Call CrLf
		
	exit
main ENDP

END main